/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

// var React = require("react");
// var {
//   AppRegistry,
//   StyleSheet,
//   Text,
//   View
// } = require("react-native");

/* ES5 语法
var Reactnative = require('react-native');
var React = require('react')
var Component = React.Component;
var AppRegistry = Reactnative.AppRegistry;
var StyleSheet = Reactnative.StyleSheet
var Text = Reactnative.Text
var View = Reactnative.View
var Son = require("./son");
*/

//es6
import React, {Component} from 'react'
 import {
   AppRegistry,
   StyleSheet,
   Text,
   View
 } from "react-native";
 import  Son  from './son';



class imoccApp extends Component{

  constructor(props){
    super(props)
    this.state = {
      times: 5,
      hit:false
    }
  }

  timePlus(){
    var times =this.state.times
    times+=3
    this.setState({
      times:times
    })
 }
  timeReset(){
    this.setState({
      times:0
    })
  }
  willHit(){
    this.setState({
      hit:!this.state.hit

    })
  }
componentWillMount(){
  console.log('ComponentWillMont','父组件即将被安装')
}
render() {
    console.log('render','父组件渲染')
  return (
    <View style={styles.container}>
      {
        this.state.hit ? <Son times={this.state.times} timeReset={this.timeReset.bind(this)}/> : null
      }

      <Text style={styles.welcome} onPress= {this.timeReset.bind(this)} >
       老子说：心情好就放你一马
      </Text>
      <Text onPress= {this.willHit.bind(this)} style={styles.instructions}>
         到底揍不揍
      </Text>
      <Text  style={styles.instructions}>
         就揍你{this.state.times}次而已
      </Text>
      <Text onPress= {this.timePlus.bind(this)} style={styles.instructions}>
         不听话，在揍三次
      </Text>
    </View>
  );
}
componentDidMount(){
    console.log('ComponentWillMont','父组件即将被安装完毕')
}
shouldComponentUpdate(){
  console.log('shouldComponentWillUpdate','父要不要更新')
  return true
}
componentWillUpdate(){
    console.log('ComponentWillMont','父组件即将被更新完毕')
}

componentDidUpdate(){
      console.log('componentDidUpdate','父组件即将被更新完毕')
  }
}
var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('imoccApp', () => imoccApp);
